package com.cn.quartz;

import org.apache.log4j.Logger;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.transaction.annotation.Transactional;

import com.cn.jms.SendSMS;
import com.cn.struts2.HttpAction;
import com.cn.struts2.SMSSendTimerAction;

public class SMSSendJob implements Job {
	public SMSSendTimerAction smsSendTimerAction;
	public HttpAction httpAction;
//	SimpleDateFormat DateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
//	Date d = new Date();
//	String returnstr = DateFormat.format(d);
	/**
	 * 打印日志
	 */
	private Logger logger = Logger.getLogger(SMSSendJob.class);


	
	public HttpAction getHttpAction() {
		return httpAction;
	}

	public void setHttpAction(HttpAction httpAction) {
		this.httpAction = httpAction;
	}

	/**
	 * 网页版提交
	 */
	@Transactional(rollbackForClassName = "Exception")
	public void execute(JobExecutionContext context) throws JobExecutionException {

		String jsonStr = context.getJobDetail().getJobDataMap().get("jsonStr").toString();
		String jobName = context.getJobDetail().getJobDataMap().get("jobName").toString();
		SendSMS sendSMS =(SendSMS)context.getJobDetail().getJobDataMap().get("sendSMS");
		SMSSendTimerAction smsSendTimerAction =(SMSSendTimerAction)context.getJobDetail().getJobDataMap().get("smsSendTimerAction");
		logger.debug("定时任务jsonStr="+jsonStr);
		logger.debug("定时任务jobName="+jobName);
		
		if (jsonStr!= null && jsonStr != "") {
			try{
				httpAction.httpchannel(jsonStr);
			}catch(Exception e)
			{
				logger.debug("e:"+e);
				e.printStackTrace();
				return ;
			}
			
			smsSendTimerAction.modifyState(jobName, "1");
		} else {
			logger.debug("json为空");
		}

	}
	
	public SMSSendJob() {
		super();
		
	}

	

}
